package com.arpa.oms.controller;

import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.map.MapUtil;
import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.controller.BaseController;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.oms.domain.dto.OmsCaptureOrderRecordDTO;
import com.arpa.oms.domain.entity.OmsCaptureOrderRecord;
import com.arpa.oms.domain.vo.OmsCaptureOrderRecordVO;
import com.arpa.oms.service.IOmsCaptureOrderRecordService;
import com.arpa.wms.domain.consts.PropertyConst;
import com.arpa.wms.domain.enums.StatusEnum;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * OMS手动抓单 Controller
 * </p>
 *
 * @author rfwang
 * @since 2021-08-11
 */
@Api(tags = "OMS手动抓单")
@RestController
@RequestMapping(value="/oms/omsCaptureOrderRecord", produces = "application/json;charset=UTF-8")
@Log4j2(topic = "business")
public class OmsCaptureOrderRecordController extends BaseController {

    @Autowired
    private IOmsCaptureOrderRecordService omsCaptureOrderRecordService;
    /**
     * 获取 手动抓单 列表
     *
     * @param omsCaptureOrderRecordDTO
     * @param request
     * @return
     */
    @ApiOperation(value = "获取 手动抓单 列表", notes = "获取 手动抓单 列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = OmsCaptureOrderRecordVO.class))
    @NeedLogin
    @GetMapping()
    public Result list(OmsCaptureOrderRecordDTO omsCaptureOrderRecordDTO, HttpServletRequest request) {
        try {
            omsCaptureOrderRecordDTO.setShipmentCode(UserUtil.getLoginWarehouseCodeOrShipmentCode());
            OmsCaptureOrderRecordVO omsCaptureOrderRecordVOSum = omsCaptureOrderRecordService.queryListSum(omsCaptureOrderRecordDTO);
            List<OmsCaptureOrderRecordVO> omsCaptureOrderRecordVOList = omsCaptureOrderRecordService.queryList(omsCaptureOrderRecordDTO);

            Page returnPage = new Page(omsCaptureOrderRecordDTO.getPageNum(),omsCaptureOrderRecordDTO.getPageSize());
            returnPage.setRecords(omsCaptureOrderRecordVOList);
            returnPage.setTotal(omsCaptureOrderRecordVOSum.getTotal());
            returnPage.setSumObject(omsCaptureOrderRecordVOSum);
            return Result.ok().data(returnPage);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }


 }
